package hejie.admin.action;

import java.util.ArrayList;
import java.util.List;

import hejie.admin.dao.RightDao;
import hejie.admin.service.OtherService;


import javax.annotation.Resource;

import publics.model.Right;
import publics.util.MyUtils;
import publics.util.Page;



import com.opensymphony.xwork2.ActionSupport;

public class OtherAction  extends ActionSupport{

	private static final long serialVersionUID = 1L;
	private RightDao rightDao;
	
	private OtherService otherService;
	
	private boolean success;   //此参数为必须的， extjs根据这个参数的值判断是否成功执行操作
	private Page page;   //这是分页查询用的辅助类，用此类可以解决分页查询中要返回多个参数的问题，推荐使用
	private String conditions;
	private int start;   //分页查询的 要查询数据的开始号 ，和offset值相同
	private int limit;  // 每页多少个记录
	private Right right;
	private Integer id;
	
	public RightDao getRightDao() {
		return rightDao;
	}
	@Resource(name="rightDao")
	public void setRightDao(RightDao rightDao) {
		this.rightDao = rightDao;
		System.out.println("RightDaoImpl inject in RightAction!");
	}
	
	public OtherService getOtherService() {
		return otherService;
	}

	@Resource(name="otherService")
	public void setOtherService(OtherService otherService) {
		this.otherService = otherService;
	}
	
	/**
	 * 查找所有权限
	 * @return
	 */
	public String findAllRight() {  
		List<String> conditionList = new ArrayList<String>();   //模糊查询使用
		MyUtils.addToCollection(conditionList, MyUtils.split(conditions, " ,"));//模糊查询使用
		page = new Page(); // 实例化分页对象
		page.setConditions(conditionList);// 设置查询条件
		page.setStart(start);
		page.setLimit(limit = (limit == 0) ? 50 : limit);
		page = otherService.findRightByPage(page);  //查询 
		if ((null != page.getRoot() && page.getTotalProperty() > 0 )||(null == page.getRoot() && page.getTotalProperty() == 0 )) {
			page.setSuccess(true);
			System.out.println("执行findAllRight() in RightAction!Success(true)");
		}else{
			page.setSuccess(false);//查找失败
		}
		return SUCCESS;	
	}

	/**
	 * 查找所有民族
	 * @return
	 */
	public String findAllEthnic() { 
		List<String> conditionList = new ArrayList<String>();   //模糊查询使用
		MyUtils.addToCollection(conditionList, MyUtils.split(conditions, " ,"));//模糊查询使用
		page = new Page(); // 实例化分页对象
		page.setConditions(conditionList);// 设置查询条件
		page.setStart(start);
		page.setLimit(limit = (limit == 0) ? 60 : limit);
		page = otherService.findEthnicByPage(page);  //查询 
		if ((null != page.getRoot() && page.getTotalProperty() > 0 )||(null == page.getRoot() && page.getTotalProperty() == 0 )) {
			page.setSuccess(true);
		}else{
			page.setSuccess(false);//查找失败
		}
		return SUCCESS;	
		 
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public Right getRight() {
		return right;
	}

	public void setRight(Right right) {
		this.right = right;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	
	public Page getPage() {
		return page;
	}
	public void setPage(Page page) {
		this.page = page;
	}
	public int getStart() {
		return start;
	}
	public void setStart(int start) {
		this.start = start;
	}
	public int getLimit() {
		return limit;
	}
	public void setLimit(int limit) {
		this.limit = limit;
	}


}
